//
//  WaiSongLunBoTuView.m
//  FD
//
//  Created by Yasin on 2018/10/20.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//
// 外送点餐轮播图view
#import "WaiSongLunBoTuView.h"
#import <SDCycleScrollView.h>
//model
#import "WaiSongWhirligigModel.h"

@interface WaiSongLunBoTuView()<SDCycleScrollViewDelegate>

/**轮播图*/
@property (nonatomic,  strong) SDCycleScrollView *cycleScrollView;

/**临时数组*/
@property (nonatomic, strong) NSArray *tempArr;
@end

@implementation WaiSongLunBoTuView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}
- (void)setupView
{
//    UIImage *img1 = [UIImage imageNamed:@"timg1.jpg"];
//    UIImage *img2 = [UIImage imageNamed:@"timg2.jpg"];
//    UIImage *img3 = [UIImage imageNamed:@"timg3.jpg"];
    
    //占位图没有 不就随便找一个图片
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:self.bounds delegate:self placeholderImage:nil];
    self.cycleScrollView.backgroundColor = [UIColor whiteColor];
    self.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.cycleScrollView];
}


#pragma mark - 代理
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    
    WaiSongWhirligigModel *model = self.tempArr[index];
    
    
    FDLog(@"WaiSongLunBoTuView %d--下标是:%@",__LINE__, model);
    
    
    if ([NSString isEmptyString:model.resource]) {
        FDLog(@"2019-2-16 1、首页轮播图补充逻辑：  判断结果字段：whirligigList.resource为空字符串式(无资源内容)时，改为不打开webview界面，直接点击无反应 商品列表页的轮播图同样处理");
        return;
    }
    
    //12-31回调
    if (self.clickWhirligigBlock) {
        self.clickWhirligigBlock(model.resource);
    }
}

#pragma mark - 接口
- (void)updateWhirligArrWithModelArr:(NSArray *)arr {
    NSMutableArray *imgArrM = [NSMutableArray array];
    
    self.tempArr = arr; //接收
    
    for (WaiSongWhirligigModel *model in arr) {
        [imgArrM addObject:model.thumbnail];
    }

    self.cycleScrollView.imageURLStringsGroup = [imgArrM copy];
}




@end
